import java.util.Scanner;

/**
 * Created With IntelliJ IDEA
 * Description:牛客网:OR44 扑克牌大小
 * <a href="https://www.nowcoder.com/practice/0a92c75f5d6b4db28fcfa3e65e5c9b3f?tpId=49&&tqId=29277&rp=1&ru=/activity/oj&qru=/ta/2016test/question-ranking">...</a>
 * User: DELL
 * Data: 2023-04-13
 * Time: 20:04
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] cards = str.split("-");
        //用于比较大小
        String temp = "34567891JQKA2";
        //将卡牌分为一个一个的牌
        String[] card1 = cards[0].split(" ");
        String[] card2 = cards[1].split(" ");
        if (cards[0].equals("joker JOKER") || cards[1].equals("joker JOKER")) {
            System.out.println("joker JOKER");
            return;
        }
        if (card1.length == card2.length) {
            //处理大小王
            if (card1.length == 1 && (card1[0].length() == 5 || card2[0].length() == 5)) {
                if (card1[0].equals("JOKER") || card2[0].equals("JOKER")) {
                    System.out.println("JOKER");
                } else if (card1[0].equals("joker") || card2[0].equals("joker")) {
                    System.out.println("joker");
                }
            } else {
                //根据第一个字符在 temp 数组中出现的先后顺序来确定大小
                if (temp.indexOf(card1[0].charAt(0)) < temp.indexOf(card2[0].charAt(0))) {
                    System.out.println(cards[1]);
                } else {
                    System.out.println(cards[0]);
                }
            }
        } else if (card1.length == 4){  //处理炸弹和别的牌比较的情况
            System.out.println(cards[0]);
        } else if (card2.length == 4) {
            System.out.println(cards[1]);
        } else {
            System.out.println("ERROR");
        }
    }
}
